import service from "../../utils/request"
import { RoleEnum } from "../../enums/Role";

export interface LoginRes {
  user: User,
  token: string
}

export interface ChangePassDto {
  old_pass: string
  new_pass: string
}

export const userLogin = async (data: UserDto): Promise<Result<LoginRes>> => await service.post(`/admin-user/login`, data)

export const getUserPage = async (page: number, user_name: string): Promise<PageResult<User>> =>
    await service.get(`/user/page?page=${page}&user_name=${user_name}`)

export const changeUserRole = async (id: string, data: { role: RoleEnum }): Promise<Result<string>> =>
    await service.patch(`/wx-user/role/${id}`, data)

export const getUserByPhone = async (phone: string): Promise<Result<ListWxUser[]>> =>
    await service.get(`/wx-user?phone=${phone}`)

export const changeUserPass = async (id: string, data: ChangePassDto): Promise<Result<string>> =>
    await service.patch(`/admin-user/changePass/${id}`, data)

